package cn.gson.boot.model.service;

import cn.gson.boot.model.dao.KehuDao;
import cn.gson.boot.model.dao.WorkDao;
import cn.gson.boot.model.mapper.KehuMapper;
import cn.gson.boot.model.mapper.WorkMapper;
import cn.gson.boot.model.pojos.User;
import cn.gson.boot.model.pojos.Work;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.*;

@Service
@Transactional(rollbackFor = Exception.class)
public class WorkService {
    @Autowired
    WorkMapper workMapper;
    @Autowired
    WorkDao workDao;
    @Autowired
    KehuMapper kehuMapper;

    //分页查询和模糊查询
    public List<Work> allworks(String workContent,String workType,int empId){
        return workMapper.allworks(workContent,workType,empId);
    }

    //员工查询
    public List<User> users(){
        System.out.println("进来了");
        System.out.println("进来了"+workMapper.allusers());
        return workMapper.allusers();
    }

    //新增
    public void addWork(Work work){
        System.out.println("新增了");
        int id = work.getWorkId();
        System.out.println("日志编号："+id);
        if(id==0){
            System.out.println("类型"+work.getWorkType());
            workDao.save(work);
        }else{
            System.out.println("修改了");
        }
    }

    //日周月报类型查询
    public Map<String,Object> workleixing(int empId){
        Map<String,Object> map = new HashMap<>();
        Integer  w1 =  workMapper.workleixing("日报",empId);
        Integer  w2 =  workMapper.workleixing("周报",empId);
        Integer  w3 =  workMapper.workleixing("月报",empId);
        List<Integer> sj = new ArrayList<>();
        sj.add(w1);sj.add(w2);sj.add(w3);
        List<String> mz = new ArrayList<>();
        mz.add("日报");mz.add("周报");mz.add("月报");
        map.put("sj",sj);map.put("mz",mz);
        return map;
    }

    //日周月报提交者统计
    public Map<String,Object> kehufuzeren(int empId){
        List<User> emp = kehuMapper.em1(empId);
        Map<String,Object> map = new HashMap<>();
        List<Integer> sj = new ArrayList<>();
        List<String> mz = new ArrayList<>();
        for(int i=0;i<emp.size();i++){
            sj.add(workDao.kehufuzeren(emp.get(i).getEmpId()));
            mz.add(emp.get(i).getEmpName());
            System.out.println("名字"+emp.get(i).getEmpName());
        }
        map.put("sj",sj);
        map.put("mz",mz);
        return map;
    }

}
